package com.soft.javase.ch12.file;

import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/14
 */
public class MyFilenameFilter implements FilenameFilter {
    @Override
    public boolean accept(File dir, String name) {
        System.out.println("dir = "+dir+" , "+"name = "+name);
        if (name.endsWith(".docx")) {
            return true;
        }
        return false;
    }
}
class Test1{
    public static void main(String[] args) {
        File file = new File("D:\\temp");
        if(file.isDirectory()){
            String[] strings = file.list(new MyFilenameFilter());
            System.out.println(Arrays.toString(strings));
        }

        System.out.println("-------------Lambda简化--------------");

        if(file.isDirectory()){
            String[] strings = file.list(((dir, name) -> name.endsWith(".txt")));
            System.out.println(Arrays.toString(strings));
        }
    }
}
